﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Xml;

namespace TSites.Xml
{
    public class TsXmlEngine
    {
        private XmlDocument _xmlDoc;
        public TsXmlEngine(String file)
        {
            _xmlDoc = new XmlDocument();
            _xmlDoc.Load(file);
        }

        public String GetContent(String keyName, String keyValue)
        {
            XmlNode root = _xmlDoc.FirstChild;
            XmlNode child;
            XmlAttribute attr;
            String result = "";

            if (root.HasChildNodes)
            {
                for (int i = 0; i < root.ChildNodes.Count; i++)
                {
                    child = root.ChildNodes[i];
                    if (child.Attributes.Count > 0)
                    {
                        for (int j = 0; j < child.Attributes.Count; j++)
                        {
                            attr = child.Attributes[j];
                            if (attr.Name.Equals(keyName) && attr.Value.Equals(keyValue))
                            {
                                result = child.InnerText;
                                break;
                            }
                        }
                    }
                }
            }
            return result;
        }
    }
}